<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="f"%>
<%@ taglib uri="/WEB-INF/tld/tag.tld" prefix="my"%>
<%@ taglib uri="/WEB-INF/tld/mobai-el-common.tld" prefix="el"%>
<!DOCTYPE html>
<html>
<head>
<meta name="renderer" content="webkit|ie-comp|ie-stand">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport"
	content="width=device-width,initial-scale=1,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no" />
<meta http-equiv="Cache-Control" content="no-siteapp" />
<!--[if lt IE 9]>
<script type="text/javascript" src="/three/static/lib/html5shiv.js"></script>
<script type="text/javascript" src="/three/static/lib/respond.min.js"></script>
<![endif]-->
<link rel="stylesheet" type="text/css"
	href="/three/static/h-ui/css/H-ui.min.css" />
<link rel="stylesheet" type="text/css"
	href="/three/static/h-ui.admin/css/H-ui.admin.css" />
<link rel="stylesheet" type="text/css"
	href="/three/lib/Hui-iconfont/1.0.8/iconfont.css" />
<link rel="stylesheet" type="text/css"
	href="/three/static/h-ui.admin/skin/default/skin.css" id="skin" />
<link rel="stylesheet" type="text/css"
	href="/three/static/h-ui.admin/css/style.css" />
<!--[if IE 6]>
<script type="text/javascript" src="/three/src/main/webapp/static/lib/DD_belatedPNG_0.0.8a-min.js" ></script>
<script>DD_belatedPNG.fix('*');</script>
<![endif]-->
<title>礼包列表</title>
<style type="text/css">
#radius {
	margin: 0 auto;
	left: -200px;
}
</style>
</head>
<body>
	<div class="page-container">
		<!-------------------------------综合查询开始---------------------------------------------------------------------------->
		<form action="/three/bnb/bag" method="post" id="form1">
			<div class="text-c">
				<span class="select-box inline"> <select name="status"
					class="select">
						<option value="">请选择状态</option>
						<option value="0">待上架</option>
						<option value="1">在售</option>
						<option value="2">下架</option>
				</select>
				</span> &nbsp;&nbsp;&nbsp;&nbsp; <input type="text" name="bagId"
					placeholder="请输入礼包编号" style="width: 250px" class="input-text">
				&nbsp;&nbsp;&nbsp;&nbsp; <input type="text" name="bagName"
					placeholder="请输入礼包名称" style="width: 250px" class="input-text">
				<button class="btn btn-success" type="submit">
					<i class="Hui-iconfont">&#xe665;</i> 查询
				</button>
			</div>
			<!--------------------------综合查询结束---------------------------------------------------------------------------->


			<!---------------------------------添加开始--------------------------------------------------->
			<div class="cl pd-5 bg-1 bk-gray mt-20">
				<span class="l"> <a class="btn btn-primary radius"
					id="bag_inser" href="#"><i class="Hui-iconfont">&#xe600;</i>添加礼包</a>
				</span>
			</div>
			<!---------------------------------添加结束--------------------------------------------------->

			<!-----------------------------------显示所有开始------------------------------------------------->
			<div class="mt-20">
				<table id="table"
					class="table table-border table-bordered table-bg table-hover table-sort table-responsive">
					<thead>
						<tr class="text-c">
							<th>礼包编号</th>
							<th>礼包名称</th>
							<th>礼包价格</th>
							<th>开卡数量</th>
							<th>剩余卡数</th>
							<th>上架时间</th>
							<th>下架时间</th>
							<th>过期时间(天)</th>
							<th>状态</th>
							<th>创建时间</th>
							<th>排序号</th>
							<th>操作</th>
						</tr>
					</thead>
					<tbody>
						<c:forEach items="${bisNurseBagList }" var="bag">
							<tr class="text-c">
								<td>${bag.bagId }</td>
								<td>${bag.bagName }</td>
								<td>${bag.bagTotalPrice }</td>
								<td>${bag.openCardNum }</td>
								<td>${bag.remainNum }</td>
								<td><f:formatDate value="${bag.putawayTime }"
										pattern="yyyy-MM-dd" /></td>
								<td><f:formatDate value="${bag.soldoutTime }"
										pattern="yyyy-MM-dd" /></td>
								<td>${bag.overdueTime }</td>
								<td class="td-status">
									<c:if test="${bag.status=='0'}"><span class="label label-disabled radius">待上架</span></c:if>
									<c:if test="${bag.status=='1'}"><span class="label label-success radius">在售</span></c:if>
									<c:if test="${bag.status=='2'}"><span class="label label-danger radius">下架</span></c:if>
								</td>
								<td><f:formatDate value="${bag.createTime }"
										pattern="yyyy-MM-dd" /></td>
								<td>${bag.sortNo }</td>
								<td class="f-14 td-manage"><a style="text-decoration: none"
									class="ml-5"
									onClick="bag_details('查看礼包信息','/three/bnb/bag_details?bagId=${bag.bagId }','10001')"
									href="javascript:;" title="查看详情"><i class="Hui-iconfont">&#xe665;</i></a>
									<a style="text-decoration: none" class="ml-5"
									onClick='bag_edit(${el:toJsonString(bag)})' href="javascript:;"
									title="编辑"><i class="Hui-iconfont">&#xe6df;</i></a> <a
									style="text-decoration: none" class="ml-5"
									onClick="bag_del('${bag.bagId }')" href="javascript:;" title="删除"><i
										class="Hui-iconfont">&#xe6e2;</i></a></td>
							</tr>
						</c:forEach>
					</tbody>
				</table>
			</div>
		</form>
		<!-----------------------------显示所有结束------------------------------------------------------->

		<!------ ----------------------添加 修改礼包信息模态框开始---------------------------------------------------- -->
		<div id="modal-demo" class="modal fade" tabindex="-1" role="dialog"
			aria-labelledby="myModalLabel" aria-hidden="true"
			style="overflow-y: scroll;">
			<div class="modal-dialog">
				<div class="modal-content radius" id="radius" style="width: 1000px">
					<div class="modal-header">
						<h3 class="modal-title">编辑礼包信息</h3>
						<a class="close" data-dismiss="modal" aria-hidden="true"
							href="javascript:void();">×</a>
					</div>
					<div class="modal-body">
						<!------ ----------------------模态框内容部分开始---------------------------------------------------- -->
						<form class="form form-horizontal" id="forms" method="post"
							enctype="multipart/form-data">
							<input type="hidden" class="input-text" name="bagId" id="bagId">
							<table>
								<tr>
									<td>
										<div class="row cl">
											<label class="form-label col-xs-3 col-sm-4"><font
												color="red">*</font>礼包名称：</label>
											<div class="formControls col-xs-6 col-sm-6">
												<input type="text" class="input-text" name="bagName">
											</div>
										</div>
									</td>
									<td>
										<div class="row cl">
											<label class="form-label col-xs-4 col-sm-3">状态：</label>
											<div class="formControls col-xs-6 col-sm-6">
												<input type="text" class="input-text" id="status" readonly="readonly">
											</div>
										</div>
									</td>
								</tr>
								<tr>
									<td>
										<div class="row cl">
											<label class="form-label col-xs-3 col-sm-4">列表图片：</label>
											<div class="formControls col-xs-6 col-sm-6">
												<span class="btn-upload form-group" id="span"> <input
													class="input-text upload-url radius" type="text"
													style="width: 185px;" name="uploadfile-1" id="1file"
													readonly> <a href="javascript:void();"
													class="btn btn-primary radius"><i class="Hui-iconfont">&#xe642;</i>
														</a> <input type="file" multiple name="files" id="file1"
													class="input-file">
												</span> <span id="span1"> <img src="" alt="请上传图片"
													id="coverPhoto" style="width: 80px;height: 50px"> <input type="hidden"
													name="coverPhoto" /> <a href="#" style="margin-top: 10px"
													class="btn btn-primary radius" id="xztp"><i
														class="Hui-iconfont">&#xe642;</i> </a>
												</span>
											</div>
										</div>
									</td>
									<td>
										<div class="row cl">
											<label class="form-label col-xs-4 col-sm-3">封面图片：</label>
											<div class="formControls col-xs-6 col-sm-6">
												<span class="btn-upload form-group" id="span2"> <input
													class="input-text upload-url radius" type="text"
													style="width: 175px;" name="uploadfile-1" id="2file"
													readonly> <a href="javascript:void();"
													class="btn btn-primary radius"><i class="Hui-iconfont">&#xe642;</i>
														</a> <input type="file" multiple name="files" id="file2"
													class="input-file">
												</span> <span id="span3"> <img src="" alt="请上传图片"
													id="coverBigPhoto" style="width: 80px;height: 50px"> <input type="hidden"
													name="coverBigPhoto" /> <a href="#"
													style="margin-top: 10px" class="btn btn-primary radius"
													id="xztp1"><i class="Hui-iconfont">&#xe642;</i></a>
												</span>
											</div>
										</div>
									</td>
								</tr>
								<tr>
									<td colspan="2">
										<div style="margin-left: 70px; margin-top: 10px">
											<label style=""><font color="red">*</font>护理项目：</label>
											<button type="button" style="margin-left: 26px"
												class="btn btn-secondary radius" onclick="modaldemo()">
												<i class="Hui-iconfont">&#xe600;</i>添加护理项目
											</button>
											<div style="margin-right: 200px" id="div">
												<table id="table1" style="margin-left: 100px"
													class="table table-border table-bordered table-bg table-hover table-sort table-responsive">
													<thead>
														<tr class="text-c">
															<th>项目名称</th>
															<th>价格（元）</th>
															<th style="width: 100px">数量</th>
															<th>操作</th>
														</tr>
													</thead>
													<tbody id="tbodyadd"></tbody>
												</table>
											</div>
										</div>
									</td>
								</tr>
								<tr>
									<td>
										<div class="row cl">
											<label class="form-label col-xs-3 col-sm-4">礼包价格：</label>
											<div class="formControls col-xs-6 col-sm-6">
												<input type="text" class="input-text" name="bagTotalPrice" id="bagTotalPrice"
													readonly="readonly">
											</div>
										</div>
									</td>
									<td>
										<div class="row cl">
											<label class="form-label col-xs-4 col-sm-3">开卡数量：</label>
											<div class="formControls col-xs-6 col-sm-6">
												<input type="text" class="input-text" name="openCardNum"
													placeholder="0-9的整数">
											</div>
										</div>
									</td>
								</tr>
								<tr>
									<td>
										<div class="row cl">
											<label class="form-label col-xs-3 col-sm-4">每次最少购买量：</label>
											<div class="formControls col-xs-6 col-sm-6">
												<input type="text" class="input-text" name="minBuyNum"
													placeholder="0-9的整数">
											</div>
										</div>
									</td>
									<td>
										<div class="row cl">
											<label class="form-label col-xs-4 col-sm-3">每次最大购买量：</label>
											<div class="formControls col-xs-6 col-sm-6">
												<input type="text" class="input-text" name="maxBuyNum"
													placeholder="0-9的整数">
											</div>
										</div>
									</td>
								</tr>
								<tr>
									<td>
										<div class="row cl">
											<label class="form-label col-xs-3 col-sm-4">允许购买次数：</label>
											<div class="formControls col-xs-6 col-sm-6">
												<input type="text" class="input-text" name="buyCount"
													placeholder="0-9的整数">
											</div>
										</div>
									</td>
									<td>
										<div class="row cl">
											<label class="form-label col-xs-4 col-sm-3">有效期(天)：</label>
											<div class="formControls col-xs-6 col-sm-6">
												<input type="text" class="input-text" name="overdueTime"
													placeholder="0-9的整数">
											</div>
										</div>
									</td>
								</tr>
								<tr>
									<td>
										<div class="row cl">
											<label class="form-label col-xs-3 col-sm-4">上架时间：</label>
											<div class="formControls col-xs-6 col-sm-6">
												<input type="date" class="input-text" name="putawayTime"
													id="putawayTime">
											</div>
										</div>
									</td>
									<td>
										<div class="row cl">
											<label class="form-label col-xs-4 col-sm-3">下架时间：</label>
											<div class="formControls col-xs-6 col-sm-6">
												<input type="date" class="input-text" name="soldoutTime"
													id="soldoutTime">
											</div>
										</div>
									</td>
								</tr>
								<tr>
									<td>
										<div class="row cl">
											<label class="form-label col-xs-3 col-sm-4">排序号：</label>
											<div class="formControls col-xs-6 col-sm-6">
												<input type="text" class="input-text" name="sortNo"
													placeholder="0-9的整数">
											</div>
										</div>
									</td>
									<td>
										<div class="row cl">
											<label class="form-label col-xs-4 col-sm-3">礼包介绍：</label>
											<div class="formControls col-xs-6 col-sm-6">
												<textarea class="textarea radius" style="white: 100px"
													rows="5" cols="10" name="bagIntroduce"></textarea>
											</div>
										</div>
									</td>
								</tr>
								<tr>
									<td colspan="2">
										<div class="row cl">
											<label class="form-label col-xs-4 col-sm-3">购买说明：</label>
											<div class="formControls col-xs-6 col-sm-6">
												<textarea class="textarea radius" style="white: 100px"
													rows="5" cols="10" name="content"></textarea>
											</div>
										</div>
									</td>
								</tr>
							</table>
						</form>
						<!------ ----------------------模态框内容部分结束---------------------------------------------------- -->
					</div>
					<div class="modal-footer">
						<button class="btn btn-secondary radius" type="button" id="but">
							<i class="Hui-iconfont">&#xe632;</i> 保存
						</button>
						<button class="btn radius" data-dismiss="modal" aria-hidden="true"
							id="guanbi">关闭</button>
					</div>
				</div>
			</div>
		</div>
		<!-- 添加 修改礼包信息模态框结束--------------------------------------------------- -->


		<!-- 点击   添加护理项目   模态框开始---------------------------------------------------- -->
		<div id="modal" class="modal fade" tabindex="-1" role="dialog"
			aria-labelledby="myModalLabel" aria-hidden="true">
			<div class="modal-dialog">
				<div class="modal-content radius" id="radius" style="width: 1000px">
					<div class="modal-header">
						<h3 class="modal-title">护理项目列表</h3>
						<a class="close" data-dismiss="modal" aria-hidden="true"
							href="javascript:void();">×</a>
					</div>
					<div class="modal-body">
						<!-- 护理项目列表开始------------------------------------- -->
						<div class="page-container">
							<form action="" method="post" id="form2">
								<!-------------------------------综合查询开始---------------------------------------------------------------------------->
								<div class="text-c">
									<span class="select-box inline"> <select name="typeId"
										id="typeId" class="select">
											<option value="">请选择分类</option>
											<c:forEach items="${listType }" var="listType">
												<option value="${listType.typeId }">${listType.typeName }</option>
											</c:forEach>
									</select>
									</span> &nbsp;&nbsp;&nbsp;&nbsp; <input type="text" name="projectId"
										id="projectId" placeholder="请输入项目编号" style="width: 250px"
										class="input-text"> &nbsp;&nbsp;&nbsp;&nbsp; <input
										type="text" name="projectName" id="projectName"
										placeholder="请输入项目名称" style="width: 250px" class="input-text">
									<button class="btn btn-success" type="button" id="butList">
										<i class="Hui-iconfont">&#xe665;</i> 查询
									</button>
								</div>
								<!--------------------------综合查询结束---------------------------------------------------------------------------->

								<div class="mt-20" style="height: 400px; overflow: auto;">
									<table
										class="table table-border table-bordered table-bg table-hover table-sort table-responsive"
										id="table2">
										<thead>
											<tr class="text-c">
												<th><input type="checkbox" name="" id="" />选择</th>
												<th>项目编号</th>
												<th>项目名称</th>
												<th>分类</th>
												<th>服务时常(分钟)</th>
												<th>人民币售价(元)</th>
												<th>颜值币售价(个)</th>
												<th>标准手工费(元)</th>
												<th>活动手工费(元)</th>
												<th>更新时间</th>
												<th>排序号</th>
											</tr>
										</thead>
										<tbody id="tbody"></tbody>
									</table>
								</div>
							</form>
						</div>
						<!-- 护理项目列表结束------------------------------------- -->
					</div>
					<div class="modal-footer">
						<button class="btn btn-primary" id="fuzhi">确定</button>
						<button class="btn" data-dismiss="modal" aria-hidden="true">关闭</button>
					</div>
				</div>
			</div>
		</div>
		<!-- 点击   添加护理项目   模态框结束--------------------------------------------------- -->
	</div>
</body>
<script type="text/javascript" src="/three/lib/jquery/1.9.1/jquery.min.js"></script>
<script type="text/javascript" src="/three/static/formEdit.js"></script>
<script type="text/javascript" src="/three/lib/layer/2.4/layer.js"></script>
<script type="text/javascript" src="/three/static/h-ui/js/H-ui.min.js"></script>
<script type="text/javascript"
	src="/three/static/h-ui.admin/js/H-ui.admin.js"></script>
<!--/_footer 作为公共模版分离出去-->

<!--请在下方写此页面业务相关的脚本-->
<script type="text/javascript"
	src="/three/lib/My97DatePicker/4.8/WdatePicker.js"></script>
<script type="text/javascript"
	src="/three/lib/datatables/1.10.0/jquery.dataTables.min.js"></script>
<script type="text/javascript" src="/three/lib/laypage/1.2/laypage.js"></script>
<script type="text/javascript"
	src="/three/lib/jquery.validation/1.14.0/jquery.validate.js"></script>
<script type="text/javascript"
	src="/three/lib/jquery.validation/1.14.0/validate-methods.js"></script>
<script type="text/javascript"
	src="/three/lib/jquery.validation/1.14.0/messages_zh.js"></script>
<script type="text/javascript"
		src="/three/lib/jquery.validation/1.14.0/additional-methods.js"></script>
<script type="text/javascript">
	/*礼包-排序*/
	$('#table').dataTable({
		"aaSorting" : [ [ 1, "desc" ] ],//默认第几个排序
		"bStateSave" : true,//状态保存
		"pading" : false,
		//"ordering":false,//thead
		"aoColumnDefs" : [
		//{"bVisible": false, "aTargets": [ 3 ]} //控制列的隐藏显示
		{
			"orderable" : false,
			"aTargets" : [ 1, 8 ]
		} // 不参与排序的列
		]
	});

	/*礼包-详情*/
	function bag_details(title, url, w, h) {
		var index = layer.open({
			type : 2,
			title : title,
			content : url,
			h : h
		});
		layer.full(index);
	};

	/*礼包-点击添加礼包按钮*/
	$("#bag_inser").on("click", function() {
		$("#modal-demo").modal("show");
		$("#span1").hide();
		$("#span3").hide();
	});
	
	/*礼包-修改赋值*/
	function bag_edit(bag) {
		//console.log(bag);
		$("#modal-demo").modal("show");
		$("#forms").formEdit(bag);
		$("#span").hide();
		$("#span1").show();
		$("#span2").hide();
		$("#span3").show();
		$("#putawayTime").val(getDate(bag.putawayTime));
		$("#soldoutTime").val(getDate(bag.soldoutTime));
		$("#coverPhoto").attr("src","http://localhost:8080/three"+bag.coverPhoto);
		$("#coverBigPhoto").attr("src","http://localhost:8080/three"+bag.coverBigPhoto);
		$("#xztp").on("click",function(){
			$("#span1").hide();
			$("#span").show();
		});
		$("#xztp1").on("click",function(){
			$("#span3").hide();
			$("#span2").show();
		});
		//根据礼包编号去桥表中查询该礼包中所有的项目  循环表格显示出来
		$.ajax({
			type : "POST",
			url : "/three/bnb/bagByBagId?bagId="+bag.bagId,
			success : function(msg) {
				$.each(msg,function(index,obj){
					console.log($(obj));
					$("#tbodyadd").append("<tr class='text-c' id='trid'>  <td>"+obj.projectName+"</td>  <td><input type='text' name='projectNewPrice' class='input-text' id='projectNewPrice' value="+obj.projectNewPrice+" /> </td>  <td><div class='formControls '><input type='text' name='projectNum' class='input-text' id='projectNum' value="+obj.projectNum+" /></div></td>  <td>   <a style='text-decoration: none' class='ml-5' onClick='project_del(this)' href='javascript:;' title='删除'><i class='Hui-iconfont'>&#xe6e2;</i></a>  <input type='hidden' name='projectId' id='projectId' value="+obj.projectId+" /></td>  </tr>");
				})
			}
		});
	};
	
	/*礼包-添加修改礼包信息*/
	$("#but").on("click",function(){
		//日期判断
		if(ckdate()!=false){
			//护理项目判断不能为空
			if($("#tbodyadd").find("tr").length<=0){
				alert("请选择护理项目!");
				return false;
			}else{
				if($("#bagId").val()==null||$("#bagId").val()==""){
					//console.log("添加");
					var soldoutTime=$("#soldoutTime").val();
					var end = new Date(soldoutTime.replace("-", "/").replace("-", "/"));
					if(end<new Date()){
						alert("下架时间不能小于今天！");
						return;
					}
					$("#forms").attr("action","/three/bnb/bag_add");
					$("#forms").submit();
				}else{
					//console.log("修改");
					$("#forms").attr("action","/three/bnb/bag_update");
					$("#forms").submit();
				}
			}
		}
	});

	/*礼包-删除*/
	function bag_del(bagId) {
		layer.confirm('确认要删除吗？', function(index) {
			//console.log(projectId);
			$("#form1").attr("action",
					"/three/bnb/bag_del?bagId=" + bagId);
			$("#form1").submit();
			layer.msg('已删除!', {
				icon : 1,
				time : 1000
			});

		});
	};
	
	/*日期取值*/
	function getDate(date) {
		if(date!=null){
			var year=date.year+1900;
			var month=date.month+1;
			if(month<10){
				month="0"+month;
			}
			var day=date.date;
			if(day<10){
				day="0"+day;
			}
			var bornDate=year+"-"+month+"-"+day;
			//console.log(bornDate);
			return bornDate;
		}	
	}
	
	/*礼包-刷新模态框*/
	$('#modal-demo').on('hidden.bs.modal', function () {
		window.location.reload();
	});
	
	/*礼包-日期格式化*/
	Date.prototype.Format = function(fmt) { //author: meizz 
		var o = {
			"M+" : this.getMonth() + 1, //月份 
			"d+" : this.getDate(), //日 
			"h+" : this.getHours(), //小时 
			"m+" : this.getMinutes(), //分 
			"s+" : this.getSeconds(), //秒 
			"q+" : Math.floor((this.getMonth() + 3) / 3), //季度 
			"S" : this.getMilliseconds()
		//毫秒 
		};
		if (/(y+)/.test(fmt))
			fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "")
					.substr(4 - RegExp.$1.length));
		for ( var k in o)
			if (new RegExp("(" + k + ")").test(fmt))
				fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k])
						: (("00" + o[k]).substr(("" + o[k]).length)));
		return fmt;
	};
	
	/*礼包-点击添加护理项目*/
	function modaldemo() {
		$("#modal").modal("show");
		$("#tbody").find("tr").eq(0).hide();
		ajax(null,null,null);
	};
	
	/*礼包-点击添加护理项目  查询*/
	$("#butList").on("click",function(){
		//console.log("查询");
		var typeId=$("#typeId").val();
		var projectId=$("#projectId").val();
		var projectName=$("#projectName").val();
		$("#tbody").empty();
		ajax(typeId,projectId,projectName);
	});
	
	/*礼包-点击添加护理项目  选中*/
	$(document).on("click","#tbody #trr",function(){
		if($(this).find("td:eq(0) #xz").attr("checked")==null){
			$(this).find("td:eq(0) #xz").attr("checked","checked");
		}else{
			$(this).find("td:eq(0) #xz").attr("checked",false);
		}
		//判断选中的projectid和  之前已经选择的projectid是否相等  如果相等提示  数据重复
		var projectid=$(this).find("td:eq(1)").html();
		$.each($("#tbodyadd #trid"),function(){
			if($(this).find(" td:eq(3) #projectId").val()==projectid){
				alert("该项目已经被选择过，如需添加可返回直接修改次数哦~");
				//不让选中
				$("#tbody #trr").find("td:eq(0) #xz").attr("checked",false);
			}	
		});
	});
	//礼包总价
	/*礼包-点击添加护理项目  赋值*/
	$("#fuzhi").on("click",function(){
		$.each($("input:checked"),function(){
			var projectId=$(this).parents("tr").find("td:eq(1)").html();
			var projectName=$(this).parents("tr").find("td:eq(2)").html();
			var projectNewPrice=$(this).parents("tr").find("td:eq(5)").html();
			$("#tbodyadd").append("<tr class='text-c' id='trid'>  <td>"+projectName+"</td>  <td><input type='text' name='projectNewPrice' class='input-text' id='projectNewPrice' value="+projectNewPrice+" /> </td>  <td><div class='formControls '><input type='text' name='projectNum' class='input-text' id='projectNum' placeholder='0-9的整数' value='1' /></div></td>  <td>  <a style='text-decoration: none' class='ml-5' onClick='project_del(this)' href='javascript:;' title='删除'><i class='Hui-iconfont'>&#xe6e2;</i></a>         <input type='hidden' name='projectId' id='projectId' value="+projectId+" /></td>  </tr>");
		});
		price();
		$("#modal").modal("hide");
	});
	
	//计算礼包价格失去焦点事件
	$(document).on("blur","#projectNewPrice",function(){
		price();
	});
	$(document).on("blur","#projectNum",function(){
		price();
	});
	
	function price() {
		var bagTotalPrice=0;
		$.each($("#tbodyadd tr"),function(){
			var projectNewPrice=$(this).find("#projectNewPrice").val();
			var projectNum=$(this).find("#projectNum").val();
			var price=projectNewPrice*projectNum;
			bagTotalPrice=bagTotalPrice+price;
		});
		$("#bagTotalPrice").val(bagTotalPrice);
	}
	 
	/*礼包-点击添加护理项目  护理项目详情*/
	function list_project(title,url){
		var index = layer.open({
			type: 2,
			title: title,
			content: url,
			h:h
		});
		layer.full(index);
	}
	
	/*礼包-点击添加护理项目  删除已选的护理项目*/
	function project_del(obj){
		$(obj).parents("#trid").remove();
		price();
	}
	
	/*礼包-点击添加护理项目  清空模态框*/
	$('#modal').on('hidden.bs.modal', function () {
		$("#tbody").empty();
	});

	/*礼包-点击添加护理项目  综合查询*/
	function ajax(typeId,projectId,projectName){
		$.ajax({
			type : "POST",
			url : "/three/bnb/bag_project_list",
			data: {"typeId":typeId,"projectId":projectId,"projectName":projectName},
			dataType : "json",
			success : function(obj) {
				for (var i = 0; i < obj.length; i++) {
					var createTime = new Date(obj[i].createTime).Format("yyyy-MM-dd hh:mm:ss");
					$("#tbody")
							.append(
									"<tr class='text-c' id='trr'>  <td><input type='checkbox' name='' id='xz' /></td>  <td>"
											+ obj[i].projectId
											+ "</td>  <td>"
											+ obj[i].projectName
											+ "</td>  <td>"
											+ obj[i].typeName
											+ "</td>  <td>"
											+ obj[i].serverTime
											+ "</td>  <td>"
											+ obj[i].rmbPrice
											+ "</td>  <td>"
											+ obj[i].beautyPrice
											+ "</td>  <td>"
											+ obj[i].manualPrice
											+ "</td>  <td>"
											+ obj[i].activePrice
											+ "</td>  <td>"
											+ createTime
											+ "</td>  <td>"
											+ obj[i].sortNo
											+ "</td>  </tr>");
				}
			}
		});
	}
	
	/*图片上传失去焦点 验证图片后缀名是否正确*/
	$("#file1").on("blur",function(){
		var file1=$("#file1").val();
		if(file1!=""){
			if(file1.endsWith(".jpg")||file1.endsWith(".png")){
				
			}else{
				alert("列表图片格式不正确！");
				$("#1file").val("");
				$("#file1").val("");
			}
		}
	});
	$("#file2").on("blur",function(){
		var file2=$("#file2").val();
		if(file2!=""){
			if(file2.endsWith(".jpg")||file2.endsWith(".png")){
				
			}else{
				alert("封面图片格式不正确！");
				$("#2file").val("");
				$("#file2").val("");
			}
		}
	});
	
	//表单验证
	$("#forms").validate({
		rules:{
			bagName:{
				required:true,
			},
			openCardNum:{
				digits:true,
			},
			minBuyNum:{      
				digits:true,
			},
			maxBuyNum:{
				digits:true,
			},
			buyCount:{
				digits:true,
			},
			overdueTime:{
				digits:true,
			},
			sortNo:{
				digits:true,
			},
			projectNewPrice:{
				number:true,
			},
			projectNum:{
				digits:true,
				min:1,
			},
			putawayTime:{
				required:true,
			},
			soldoutTime:{
				required:true,
			}
		},
		onkeyup:false,
		focusCleanup:true,
	});	
	$("#putawayTime").on("blur",function(){
		ckdate();
	})
	$("#soldoutTime").on("blur",function(){
		ckdate();
	})
	/*添加  日期判断*/
	function ckdate() {
		var putawayTime=$("#putawayTime").val();//上架时间
		var soldoutTime=$("#soldoutTime").val();
		
		var start = new Date(putawayTime.replace("-", "/").replace("-", "/"));
		var end = new Date(soldoutTime.replace("-", "/").replace("-", "/"));
		if(end<start){  
			alert("开始时间必须小于结束时间！！！");
			return false;
		}else if(start>new Date()){//待上架
			$("#status").val("待上架");
		}else if(start<=new Date()&&end>=new Date()){//上架
			$("#status").val("上架");
		}else if(end<new Date()){//下架
			$("#status").val("下架");
		}
		return true;
	}
</script>
</html>